package com.bw.app.func;


import com.bw.common.utils.KeywordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;

@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public class SplitFunction extends TableFunction<Row> {  //SplitFunction(辉煌八维大数据)
    public void eval(String str) {
        List<String> list = null;
        try {
            //IK分词器
            list = KeywordUtil.splitKeyword(str); //[小米，手机，华为]
            for (String word : list) {
                collect(Row.of(word));  //辉煌八维大数据         辉煌
            }
        } catch (IOException e) {
            collect(Row.of(str));
        }
    }
}

